<script setup lang="ts">
import { ref, onMounted } from 'vue'
import * as echarts from 'echarts'

const echartsRef = ref()

onMounted(() => {
  let myCharts = echarts.init(echartsRef.value)

  // 设置实例
  myCharts.setOption({
    // 标题
    // title: {
    //   text: '比例图',
    //   textStyle: {
    //     color: 'skyblue',
    //   },
    //   // left: '30%'
    // },
    // x | y轴
    xAxis: {
      show: false,
      min: 0,
      max: 100,
    },
    yAxis: {
      show: false,
      type: 'category', // 主轴
    },
    // 系列：决定展示什么图形
    series: [
      {
        type: 'bar', // 系列
        data: [58],
        barWidth: 20,
        z: 5,
        itemStyle: {
          color: 'skyblue',
          borderRadius: 20
        }
      },
      {
        type: 'bar', // 系列
        data: [100],
        barWidth: 20,
        // 调整女性柱状图的位置
        barGap: '-100%',
        z: 1,
        itemStyle: {
          color: 'pink',
          borderRadius: 20
        }
      },
    ],
    // 布局组合：
    grid: {
      left: 0,
      right: 0,
      top: 0,
      bottom: 0,
    },
  })
})
</script>

<template>
  <div class="sex">
    <div class="top">
      <p class="title">男女比例</p>
      <p class="bg"></p>
    </div>

    <div class="people">
      <div class="man">
        <img src="../../images/man.png" alt="" />
      </div>
      <div class="woman">
        <img src="../../images/woman.png" alt="" />
      </div>
    </div>

    <div class="rate">
      <p>男性比例58%</p>
      <p>女性比例42%</p>
    </div>

    <div class="charts" ref="echartsRef"></div>
  </div>
</template>

<style lang="scss" scoped>
.sex {
  width: 100%;
  height: 100%;
  background: url('../../images/dataScreen-main-lb.png') no-repeat;
  background-size: 100% 100%;
  margin: 20px 0;

  .top {
    margin-left: 20px;
    color: #fff;
    overflow: hidden;
    font-size: 20px;

    .bg {
      width: 68px;
      height: 7px;
      background: url('../../images/dataScreen-title.png') no-repeat;
      background-size: 100%;
      margin-top: 10px;
    }
  }

  .people {
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 20px 0;

    .man {
      display: flex;
      justify-content: center;
      align-items: center;
      width: 110px;
      height: 115px;
      margin-right: 50px;
      background: url('../../images/man-bg.png') no-repeat;
      background-size: 100% 100%;
    }

    .woman {
      display: flex;
      justify-content: center;
      align-items: center;
      width: 110px;
      height: 115px;
      background: url('../../images/woman-bg.png') no-repeat;
      background-size: 100% 100%;
    }
  }

  .rate {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 80%;
    color: #fff;
    margin: 0 auto;

    p {
      flex: 1;

      &:first-child {
        text-align: left;
      }
      &:last-child {
        text-align: right;
      }
    }
  }

  .charts {
    height: 100px;
    width: 80%;
    margin: 0 auto;
  }
}
</style>
